//
//  NewEventTimeCell.swift
//  YOKO
//
//  Created by Zoe_G on 16/5/13.
//  Copyright © 2016年 15Tec. All rights reserved.
//

import UIKit
import SnapKit

class NewEventTimeCell: NewEventViewBasicCell {
    
    @IBOutlet weak var title: UILabel!
    @IBOutlet weak var switchBtn: UIButton!
    @IBOutlet weak var dateBtn: UIButton!
    @IBOutlet weak var timeBtn: UIButton!
    
    var dateBtnHighlightedView: UIView!
    var timeBtnHighlightedView: UIView!
    
    var dateBtnHighlighted: Bool {
        get { return !dateBtnHighlightedView.hidden }
        set {
            dateBtnHighlightedView.hidden = !newValue
        }
    }
    
    var timeBtnHighlighted: Bool {
        get { return !timeBtnHighlightedView.hidden }
        set {
            timeBtnHighlightedView.hidden = !newValue
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        switchBtn.setImage(UIImage(named: "switch"), forState: .Normal)
        switchBtn.setImage(UIImage(named: "switch-highlight"), forState: .Selected)
        
        dateBtnHighlightedView = UIView()
        dateBtnHighlightedView.backgroundColor = YOKOColor.TypeColors[0]
        dateBtnHighlightedView.opaque = true
        dateBtn.addSubview(dateBtnHighlightedView)
        dateBtnHighlightedView.snp_makeConstraints {
            make in
            make.left.equalTo(dateBtn)
            make.right.equalTo(dateBtn)
            make.bottom.equalTo(dateBtn)
            make.height.equalTo(1.5)
        }
        dateBtnHighlighted = false
        
        timeBtnHighlightedView = UIView()
        timeBtnHighlightedView.backgroundColor = YOKOColor.TypeColors[0]
        timeBtnHighlightedView.opaque = true
        timeBtn.addSubview(timeBtnHighlightedView)
        timeBtnHighlightedView.snp_makeConstraints {
            make in
            make.left.equalTo(timeBtn)
            make.right.equalTo(timeBtn)
            make.bottom.equalTo(timeBtn)
            make.height.equalTo(1.5)
        }
        timeBtnHighlighted = false
        // Initialization code
    }
    
    override func drawRect(rect: CGRect) {
        
        title.text = self.cellTitle
        if hasSwitchBtn {
           switchBtn.hidden = false
        } else {
            switchBtn.hidden = true
        }
    }
    
    @IBAction func switchEndDate(sender: UIButton) {
        sender.selected = !sender.selected
        self.delegate.switchEndDate(sender.selected)
    }
    
    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    func cancelAllHighlighted() {
        dateBtnHighlighted = false
        timeBtnHighlighted = false
    }
}
